package com.cancer.share.controller;

import com.cancer.share.db.entity.City;
import com.cancer.share.db.mapper.CityMapper;
import com.cancer.share.db.mapper.OrderMapper;
import com.dangdang.ddframe.rdb.sharding.id.generator.IdGenerator;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * Created by zhoujian oppn 2018/6/29
 *
 * @Desc 类描述.
 */
@Controller
public class ShareController {


   @Resource
   CityMapper cityMapper;

   @Resource
   OrderMapper orderMapper;

   @Autowired
   private IdGenerator idGenerator;

   @RequestMapping("test")
   @ResponseBody
   public String test(  ){
      List<City> list = null;
      try {
         list = cityMapper.findAll();
      } catch (Throwable e) {
         e.printStackTrace();
      }
      return list.toString();
   }


   @RequestMapping("save")
   @ResponseBody
   public String save(@Param("name") String name){
      try {
         City c = new City();
         c.setId(idGenerator.generateId().longValue());
          c.setName(name);
         cityMapper.save(c);
      } catch (Throwable e) {
         e.printStackTrace();
         return "error";

      }
      return "ok";
   }


   @RequestMapping("sav")
   @ResponseBody
   public String sav(@Param("name") String name){
      try {
         orderMapper.save(idGenerator.generateId().longValue());

      } catch (Throwable e) {
         e.printStackTrace();
         return "error";

      }
      return "ok";
   }




}
